package com.wiscamp.ninechapters.problems.math;

import com.wiscamp.ninechapters.common.core.ParseHelper;
import lombok.Data;

import java.io.Serializable;

/**
 * 比
 */
@Data
public class LatexRatio implements Serializable {
    /**
     * 比的分母
     */
    private int denominator = 0;

    /**
     * 比的分子
     */
    private int numerator = 0;


    public String getLatex() {
        return numerator + ":" + denominator;
    }

    public LatexRatio(int numerator, int denominator) {
        this.denominator = denominator;
        this.numerator = numerator;
    }

    public LatexRatio(String numeratorText, String denominatorText) {
        this.denominator = ParseHelper.parseInteger(denominatorText);
        this.numerator = ParseHelper.parseInteger(numeratorText);
    }

    public LatexRatio(String content) {
        var array = content.split(":");
        if (array.length == 2) {
            this.denominator = ParseHelper.parseInteger(array[0]);
            this.numerator = ParseHelper.parseInteger(array[1]);
        }
    }
}
